package com.cx.service.czw.impl;

import com.cx.mapper.UserMapper;
import com.cx.pojo.User;
import com.cx.pojo.UserExample;
import com.cx.service.czw.UserInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserInfoImpl implements UserInfoService {

    @Autowired
    UserMapper userMapper;

    @Override
    public User selectUserInfo(String phone) {
        UserExample userExample = new UserExample();
        userExample.createCriteria().andUserPhoneEqualTo(phone);
        List<User> userList = userMapper.selectByExample(userExample);
        if(null !=userList.get(0)){
            return userList.get(0);
        }
        return null;
    }

    @Override
    public int updateUserInfo(String phone , User user) {
        UserExample userExample = new UserExample();
        userExample.createCriteria().andUserPhoneEqualTo(phone);
        int affectRows = userMapper.updateByExampleSelective(user ,userExample);
        if(0 != affectRows){
            return affectRows;
        }
        return 0;
    }
}
